<template>
  <div class="app-container">
    <div class="product">
      <div class="pro-l">
        <el-tree
          :data="twoClassify"
          node-key="names"
          highlight-current
          :props="{label: 'names',children:'list'}"
          @current-change="handleNodeClick"
        ></el-tree>
      </div>
      <div class="pro-r">
        <div class="zd3-title">
          <p>
            <span>耗材名称</span>
            <el-input v-model="searchData.names" type="text" class="userselecr" placeholder="请输入资产名称" />
          </p>
          <!-- <p>
            <span>资产名称</span>
            <el-input v-model="searchData.suppliesName" type="text" class="userselecr" placeholder="请输入处理人" />
          </p> -->
          <el-button size="small" type="success" @click="searchlist">查询</el-button>
          <el-button size="small" @click="resetList">重置</el-button>
          <el-button size="small" type="primary" @click="addPermission" v-if="userInfo.roleList[0].roleName !== 'dfZongjian'">新增</el-button>
        </div>
        <el-table
          :data="tableData"
          border
          style="width: 100%"
          height="515"
        >
          <el-table-column type="index" align="center" label="序号" width="50" fixed="left"/>
          <el-table-column align="center" prop="status" width="100" label="资产状态">
            <template slot-scope="scope">
              <div class="orderStatus">
                <p :class="scope.row.num*1 < scope.row.anquanDowm*1 ? 'red' : 'green'">{{scope.row.num*1 < scope.row.anquanDowm*1 ? '紧缺' : '正常'}}</p>
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" label="照片">
            <template slot-scope="scope">
              <img :src="scope.row.imgurl" alt="" class="avatar">
            </template>
          </el-table-column>
          <el-table-column align="center" label="二维码">
            <template slot-scope="scope">
              <img :src="scope.row.erweima" alt="" class="avatar">
            </template>
          </el-table-column>
          <el-table-column align="center" width="150" prop="bianma" label="物品编码"/>
          <el-table-column align="center" width="150" prop="names" label="物品名称"/>
          <el-table-column align="center" width="150" prop="cangk" label="所属仓库"/>
          <el-table-column align="center" width="150" prop="propertyType" label="商品条码"/>
          <el-table-column align="center" width="200" label="规格型号" >
						<template slot-scope="scope">
							<div class="ellisp">{{scope.row.guige}}</div>
						</template>
					</el-table-column>
          <el-table-column align="center" prop="danwei" label="单位" />
          <el-table-column align="center" prop="unitPrice" label="单价" />
          <el-table-column align="center" prop="num" label="数量" />
          <el-table-column align="center" width="120" prop="anquanUp" label="安全库存上限" />
          <el-table-column align="center" width="120" prop="anquanDowm" label="安全库存下限" />
          <!-- <el-table-column align="center" prop="companys" label="禁用" /> -->
          <el-table-column align="center" width="150" label="备注" >
						<template slot-scope="scope">
							<div class="ellisp">{{scope.row.remarks}}</div>
						</template>
					</el-table-column>
          <el-table-column align="center" width="100" label="操作" fixed="right">
            <template slot-scope="scope">
							<el-button type="text" size="small" v-if="userInfo.roleList[0].roleName !== 'dfZongjian'" :disabled="scope.row.wxstatus == '已完成'" @click="write(scope.row,scope.$index)">编辑</el-button>
              <el-popconfirm
                placement="top"
                hideIcon
                title="是否要删除此行？"
                @onConfirm="deleteRow(scope.row)"
              >
                <el-button type="text" size="small" slot="reference">删除</el-button>
              </el-popconfirm>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          background
					align="right"
					:page-size="50"
          layout="prev, pager, next"
          :total="total"
					@current-change='goPage'
          @prev-click="goPrev"
          @next-click="goNext"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { selectHaocaiFenlei,selectHaocaiZichan,deleteHaocaiZichan } from '@/api/caigou'
export default {
  data(){
    return{
      total: 1,
      page: 1,
      showHeader: true,
      loading: true,
      tableData: [],   //数据列表
      twoClassify: [],  //分类列表
      searchData: {},
      userInfo: ''
    }
  },
  mounted(){
    this.userInfo = this.$store.state.user.userInfo[0]
    this.getClassify()
    this.getAsset()
  },
  methods: {
    /**
     * 新增资产
     */
    addPermission(){
      this.$router.push({
        name: 'Writehaocaizichan'
      })
    },
    /**
     * 编辑资产
     */
    write(item){
      this.$router.push({
        name: 'Writehaocaizichan',
        params: {
          options: JSON.stringify(item)
        }
      })
    },
    resetList(){
      this.searchData = {}
    },
    searchlist(){
      this.getAsset()
    },
    /**
     * 获取资产列表
     */
    getAsset(type) {
      console.log(type)
      this.loading = true
      selectHaocaiZichan({
        parentId: type ? type : null,
        names: this.searchData.names ? this.searchData.names : null
      }).then((res) => {
        console.log(res);
        let temparr = res.data.list
        this.tableData = temparr
        this.loading = false
      });
    },
    /**
     * 获取资产分类
     */
    getClassify(){
      selectHaocaiFenlei({}).then(res => {
        console.log('资产分类',res)
        this.twoClassify = res.data
        this.threeloading = false
      })
    },
    delete(row){
      console.log(row)
      deleteHaocaiZichan().then(res => {
        console.log(res)
      })
    },
    /**
     * 点击分类菜单获取对应商品
     */
    handleNodeClick(data) {
      console.log(data)
      this.getAsset(data.ids)
    },
    goPrev(page) {
      console.log(page)
      this.page--
      this.getAsset()
    },
    goNext(page) {
      console.log(page)
      this.page++
      this.getAsset()
    },
    goPage(page){
      console.log(page)
      this.page = page
      this.getAsset()
    },
  }
}
</script>

<style scoped lang="scss">
.avatar{
  width: 30px;
  height: 30px;
}
.orderStatus {
  display: flex;
	justify-content: center;
  > p {
    padding: 0px 5px;
    color: #fff;
    font-size: 12px;
    border-radius: 2px;
    margin: 0 0px 0 0;
  }
  .blue {
    background: #3a87ad;
  }
  .green {
    background: #18a05e;
  }
  .yellow {
    background: #ff7a0e;
  }
  .red {
    background: #c60000;
  }
  .zise{
    background: #c7ab10
  }
}
.ellisp{
	width: 100%;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	overflow: hidden;
	text-align: center;
}
.zd3-title {
	height: 70px;
	display: flex;
	align-items: center;
	padding: 0 20px;
	position: relative;
	background: #ffffff;
	border-radius: 8px;
	// border: 1px solid rgba(0, 0, 0, 0.1);

	> p {
		font-size: 14px;
		color: #333;
		margin-right: 10px;
    display: flex;
    align-items: center;
		> span {
			padding-right: 10px;
      width: 90px;
      text-align: right;
		}
    /deep/.el-input__inner {
      width: 150px;
      background: none;
      height: 32px;
      color: #333;
      border: 1px solid rgba(0, 0, 0, 0.1);
      padding: 0 25px;
    }
    /deep/.el-input__icon {
      line-height: 32px;
    }
    .userselect {
      flex: 1;
    }

		> input {
			width: 150px;
			height: 32px;
			// background: #ccc;
			border-radius: 3px;
			border: 1px solid #ccc;
			padding-left: 10px;
			color: #333;
		}
	}
}
/deep/.el-tree {
  width: 93%;
}
/deep/.el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #18a05e;
  color: #fff;
}
/deep/.btn-prev:after {
  content: "上一页";
}
/deep/.btn-next:before {
  content: "下一页";
}
/deep/.btn-prev,
/deep/.btn-next {
  width: 65px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}
.product{
  background: #fff;
  border-radius: 8px;
  padding: 15px;
  overflow: hidden;
  border: 1px solid rgba(0,0,0,.1);
  display: flex;
  .pro-l{
    width: 200px;
  }
  .pro-r{
    flex: 1;
    overflow: hidden;
    border: 1px solid #ccc;
    border-radius: 8px;
    /deep/.el-table--enable-row-hover .el-table__body tr:hover>td {
      background-color: rgba(24,160,94,.2);
    }
    /deep/.el-table td{
      padding: 5px 0;
    }
    /deep/.el-table tr{
      cursor: pointer;
    }
    /deep/.el-table__body tr.current-row>td {
      background-color: rgba(24,160,94,.4);
    }
  }
}
</style>